<template>
	<view class="content">
		<slot></slot>
		<!-- 商品列表 -->
		<view class="tjtitle_lists">
			<view v-for="(item,index) of shoplist" :key="index" class="tjtitle_lists_li" @click="particulars(item.goods_id)">
				<image style="width: 100%;" mode="widthFix" :src="shoopimg[index].pics_big"></image>
				<text class="tjtitle_lists_li_title">{{item.goods_name}}</text>
				<view class="tjtitle_lists_li_picot">
					<view class="tjtitle_lists_li_picot_left">
						<text class="tjtitle_lists_li_picot_left_new">￥{{item.goods_price}}</text>
						<text class="tjtitle_lists_li_picot_left_old">￥{{item.goods_price+100}}</text>
					</view>
					<image style="width: 30rpx;" mode="widthFix" src="http://localhost:3000/img/j1.png"></image>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 商品列表
				shoplist:[],
				shoopimg:[]
			};
		},
		created() {
			this.getshooplist("4K超高清")
		},
		methods:{
			// 获取商品列表
			getshooplist(query){
				uni.request({
					url:"http://localhost:3001/goods_title",
					data:{
						query:query
					},
					method:"GET",
					success: (res) => {
						this.shoplist=res.data.data
						this.getshoopimg(res.data.data)
						// console.log(this.shooplist)
					}
				})
			},
			// 获取商品列表的图片地址
			getshoopimg(shooplist){
				if(shooplist.length){
					var imgobj=[]
					shooplist.forEach(item=>{
						uni.request({
							url:"http://localhost:3001/goods_img",
							data:{id:item.goods_id},
							method:"GET",
							success: (res) => {
								imgobj.push(res.data.data[0])
							}
						})
					})
					this.shoopimg=imgobj
					// console.log(this.shoopimg)
				}
			},
			// 点击商品,进入详情页面
			particulars(item){
				uni.navigateTo({
					url:"../../pages/particulars/particulars?item="+item
				})
			}
		}
	}
</script>

<style>
	.content{
		width: 750rpx;
		background-color: #f3f3f3;
	}
	.tjtitle_lists{
		display: flex;
		flex-wrap: wrap;
		margin: 0 20rpx;
	}
	.tjtitle_lists_li{
		width: 345rpx;
		background:#ffffff;
		border-radius: 10rpx;
		margin-bottom: 20rpx;
		padding: 20rpx;
		box-sizing: border-box;
	}
	.tjtitle_lists_li:nth-child(2n+1){
		margin-right: 20rpx;
	}
	.tjtitle_lists_li_title{
		display: block;
		font-size: 16rpx;
		line-height: 24rpx;
	}
	.tjtitle_lists_li_picot{
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-top: 20rpx;
	}
	.tjtitle_lists_li_picot_left{
		
	}
	.tjtitle_lists_li_picot_left_new{
		font-size: 18rpx;
		color: red;
		margin-right: 10rpx;
		font-weight: 900;
	}
	.tjtitle_lists_li_picot_left_old{
		font-size: 16rpx;
		color: #808080;
		text-decoration: line-through;
	}
	image{
		vertical-align: middle;
	}
</style>
